classdef GaussIntegrationRule < IntegrationRule
    % GAUSSINTEGRATIONRULE 高斯积分规则
    
    methods
        function obj = GaussIntegrationRule(order)
            obj.Order = order;
        end
        
        function [points, weights] = getPointsWeights(obj)
            % 获取高斯积分点和权重
            switch obj.Order
                case 1 % 1×1积分
                    points = [0, 0];
                    weights = 4;
                case 2 % 2×2积分
                    a = 1/sqrt(3);
                    points = [-a, -a; -a, a; a, -a; a, a];
                    weights = [1; 1; 1; 1];
                case 3 % 3×3积分
                    a = sqrt(0.6);
                    w1 = 5/9;
                    w2 = 8/9;
                    points = [-a, -a; -a, 0; -a, a;
                               0, -a;  0, 0;  0, a;
                               a, -a;  a, 0;  a, a];
                    weights = [w1*w1; w1*w2; w1*w1;
                               w2*w1; w2*w2; w2*w1;
                               w1*w1; w1*w2; w1*w1];
                otherwise
                    error('Gauss integration order %d not supported', obj.Order);
            end
        end
        
        function n = getNumberOfPoints(obj)
            % 获取积分点数量
            n = obj.Order^2;
        end
    end
end